{% extends 'mold/base.html' %}
{% block content %}
    <div class="row">
        <div class="col"><h5>查询</h5></div>
    </div>
    <div class="row">
        <form id="ff">
            {% csrf_token %}
            <div class="col">

                <label for="start">开始</label>
                <input class="form-control" type="date" id="start" name="start" required>
            </div>
            <div class="col">
                <label for="start">截止</label>
                <input class="form-control" type="date" id="start" name="end" required>
            </div>
            <div>
                <button type="submit">查询</button>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col" id="content"><!-- 查询内容 --></div>
    </div>
{% endblock %}
{% block script %}
    <script>
        $(document).ready(function () {
            // csrf
            let csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();

            function csrfSafeMethod(method) {
                // these HTTP methods do not require CSRF protection
                return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
            }

            $.ajaxSetup({
                beforeSend: function (xhr, settings) {
                    if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                        xhr.setRequestHeader("X-CSRFToken", csrftoken);
                    }
                }
            });
            $('#ff').submit(function (evt) {
                evt.preventDefault();
                $.post('/q/',
                    $('#ff').serialize(),
                    function (data) {
                        console.log(data);
                        if (data.success) {
                            $('#content').html(data.content);
                        }
                    }
                );
            });
        });
    </script>
{% endblock %}